package cn.mistorange.controller;


import cn.mistorange.pojo.Bill;
import cn.mistorange.pojo.BillsQueryParam;
import cn.mistorange.pojo.Result;
import cn.mistorange.service.BillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/bills")
public class BillController {

    @Autowired
    private BillService billService;

//    分页查询所有账单
//    @GetMapping





    //增加账单
    @PostMapping
    public Result addBill(Bill bill) {
        billService.addBill(bill);
        return Result.success();
    }

    //查询账单
    @GetMapping("/{id}")
    public Result getBillById(@PathVariable Integer id) {
        Bill bill = billService.getBillById(id);
        return Result.success(bill);
    }

    //删除账单
    @DeleteMapping("/{id}")
    public Result deleteBill(@PathVariable Integer id) {
        billService.deleteBill(id);
        return Result.success();
    }

    //更新账单
    @PutMapping
    public Result updateBill(Bill bill) {
        billService.updateBill(bill);
        return Result.success();
    }

    //获取所有账单
    @GetMapping("/list")
    public Result getAllBills() {
        List<Bill> bills = billService.getAllBills();
        return Result.success(bills);
    }
}
